<template>
  <el-dialog title="编辑" :visible.sync="visible" width="60%">
    <el-scrollbar style="height: 600px;">
      <quill-editor v-model="fileContent" contentType="html" style="height: 500px;"></quill-editor>
    </el-scrollbar>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="saveChanges">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import QuillEditor from 'vue-quill-editor/src/editor.vue';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

export default {
  components: {
    QuillEditor
  },
  props: ['row'],
  data() {
    return {
      visible: false,
      fileContent: ''
    };
  },
  watch: {
    row(newVal) {
      if (newVal && newVal.fileContent) {
        this.fileContent = newVal.fileContent;
      }
    }
  },
  methods: {
    open(row) {
      this.fileContent = row.fileContent;
      this.visible = true;
    },
    closeDialog() {
      this.visible = false;
    },
    saveChanges() {
      this.$emit('save', { ...this.row, fileContent: this.fileContent });
      this.closeDialog();
    }
  }
};
</script>
